import React from 'react';
import { Row, Col, Form, Input, message, Button } from 'antd';
const R = require('ramda');
const FormItem = Form.Item;


export default Form.create({ wrappedComponentRef: true })(class ExtraInfo extends React.Component {

    constructor(props) {
        super(props);
    }

    handleConfirm = () => {
        this.props.form.validateFields({ force: true }, (errors, values) => {
            if (errors) return;
            let dataSource = this.props.dataSource ? this.props.dataSource : {};
            values.cstId = this.props.cstid;
            values.id = dataSource && dataSource.id ? dataSource.id : undefined;
            this.props.dispatch({
                type: values.id ? 'customerManage/updateCustomerExtra' : 'customerManage/createCustomerExtra',
                payload: {
                    ...values,
                    onSuccess: () => {
                        // this.props.dispatch({ type: 'customerManage/getCustomerById', payload: { id: this.props.cstid, isApproval: true } });
                        if (this.props.handleReUpdateExtra) this.props.handleReUpdateExtra(false);
                    }
                }
            })
        });
    }

    handleResetFields = () => {
        this.props.form.resetFields();
        if (this.props.handleReUpdateExtra) this.props.handleReUpdateExtra(false);
    }

    render() {
        const { getFieldDecorator } = this.props.form;
        let dataSource = R.isNil(this.props.dataSource) ? {} : this.props.dataSource;
        let formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 } };
        return (
            <Form>
                <FormItem {...formItemLayout} label="交易历史" hasFeedback>
                    {getFieldDecorator('bizHistory', {
                        rules: [{
                            required: true, message: '请输入交易历史',
                        }],
                        initialValue: dataSource.bizHistory
                    })(
                        <Input disabled={(this.props.disabled || dataSource.id) && !this.props.extraUpdating} maxLength="100"
                               placeholder="范例：客户通过一达通出口，合作2年，由于XXX原因终止合作"
                        />
                    )}
                </FormItem>
                <FormItem {...formItemLayout} label="配合程度" hasFeedback>
                    {getFieldDecorator('coordinate', {
                        rules: [{
                            required: true, message: '请输入配合程度',
                        }],
                        initialValue: dataSource.coordinate
                    })(
                        <Input disabled={(this.props.disabled || dataSource.id) && !this.props.extraUpdating} maxLength="100"
                               placeholder="范例：客户能否提供完整的出口信息表/货物申报要素等"
                        />
                    )}
                </FormItem>
                <FormItem {...formItemLayout} label="产品种类" hasFeedback>
                    {getFieldDecorator('prodType', {
                        rules: [{
                            required: true, message: '请输入产品种类',
                        }],
                        initialValue: dataSource.prodType
                    })(
                        <Input disabled={(this.props.disabled || dataSource.id) && !this.props.extraUpdating} maxLength="100"
                               placeholder="范例：客户出口产品种类及常用海关编码"
                        />
                    )}
                </FormItem>
                <FormItem {...formItemLayout} label="收汇方式" hasFeedback>
                    {getFieldDecorator('forexType', {
                        rules: [{
                            required: true, message: '请输入收汇方式',
                        }],
                        initialValue: dataSource.forexType
                    })(
                        <Input disabled={(this.props.disabled || dataSource.id) && !this.props.extraUpdating} maxLength="100"
                               placeholder="范例：主要付汇地区、付汇方式和付汇时间"
                        />
                    )}
                </FormItem>
                <FormItem {...formItemLayout} label="服务类型" hasFeedback>
                    {getFieldDecorator('serviceType', {
                        rules: [{
                            required: true, message: '请输入服务类型',
                        }],
                        initialValue: dataSource.serviceType
                    })(
                        <Input disabled={(this.props.disabled || dataSource.id) && !this.props.extraUpdating} maxLength="100"
                               placeholder="范例：物流/退/免税/市场采购/金融/信用证/托收等"
                        />
                    )}
                </FormItem>
                <FormItem {...formItemLayout} label="出货频次/量" hasFeedback>
                    {getFieldDecorator('orderFrequency', {
                        rules: [{
                            required: true, message: '请输入出货频次/量',
                        }],
                        initialValue: dataSource.orderFrequency
                    })(
                        <Input disabled={(this.props.disabled || dataSource.id) && !this.props.extraUpdating} maxLength="100"
                               placeholder="范例：每月两个40GP货柜，出口货值20万美金"
                        />
                    )}
                </FormItem>
                <FormItem {...formItemLayout} label="预估收益" hasFeedback>
                    {getFieldDecorator('benefit', {
                        rules: [{
                            required: true, message: '请输入预估收益',
                        }],
                        initialValue: dataSource.benefit
                    })(
                        <Input disabled={(this.props.disabled || dataSource.id) && !this.props.extraUpdating} maxLength="100"
                               placeholder="范例：出口退税垫资报价5分，预计年收益40万RMB；物流报价XXX，预计年收益XX万RMB"
                        />
                    )}
                </FormItem>
                <FormItem {...formItemLayout} label="流程讲解" hasFeedback>
                    {getFieldDecorator('train', {
                        rules: [{
                            required: true, message: '请输入流程讲解',
                        }],
                        initialValue: dataSource.train
                    })(
                        <Input disabled={(this.props.disabled || dataSource.id) && !this.props.extraUpdating} maxLength="100"
                               placeholder="范例：已经讲解出口报关、收结外汇、退税垫资的流程；其他业务暂未涉及"
                        />
                    )}
                </FormItem>
                <FormItem {...formItemLayout} label="交易习惯分析" hasFeedback>
                    {getFieldDecorator('businessAnalysis', {
                        rules: [{
                            required: true, message: '请输入交易习惯分析',
                        }],
                        initialValue: dataSource.businessAnalysis
                    })(
                        <Input.TextArea disabled={(this.props.disabled || dataSource.id) && !this.props.extraUpdating} autosize={{ minRows: 3 }} maxLength="200"
                                        placeholder="范例：客户对价格较为敏感，进行了多次长时间议价；客户对于结汇时间要求很高；客户对于退税单证的合规性不太在意；客户大部分的货物都是拼柜，且无法提供对应单证；客户对于产地证和报关费的底价非常了解，我司只能加收每票50元操作费"
                        />
                    )}
                </FormItem>
                <FormItem {...formItemLayout} label="工作量评估" hasFeedback>
                    {getFieldDecorator('workload', {
                        rules: [{
                            required: true, message: '请输入工作量评估',
                        }],
                        initialValue: dataSource.workload
                    })(
                        <Input.TextArea disabled={(this.props.disabled || dataSource.id) && !this.props.extraUpdating} autosize={{ minRows: 3 }} maxLength="300"
                                        placeholder="范例：客户是快递出口，每个月30单，每单金额约500USD；客户需要我司协助产品归类；客户需要出产地证；客户需要收信用证或托收交单；客户需要投保信用险和货运险；客户需要做产品认证"
                        />
                    )}
                </FormItem>
                <FormItem {...formItemLayout} label="其他需求" hasFeedback>
                    {getFieldDecorator('otherRequirement', {
                        rules: [{
                            required: true, message: '请输入其他需求',
                        }],
                        initialValue: dataSource.otherRequirement
                    })(
                        <Input.TextArea disabled={(this.props.disabled || dataSource.id) && !this.props.extraUpdating} autosize={{ minRows: 3 }} maxLength="200"
                                        placeholder="客户的其他需求"
                        />
                    )}
                </FormItem>
            </Form>
        )
    }
})